
import { Inject, Controller ,Post, Body } from '@midwayjs/decorator';
import { Context } from '@midwayjs/koa';
import { ApiBearerAuth } from '@midwayjs/swagger';
import { InjectEntityModel } from '@midwayjs/typeorm';


import { Validate } from '@midwayjs/validate';
import { loginDTO } from 'src/dto/login';
import { novellistDTO, novelnumDTO } from 'src/dto/novel';
import { NovelEntity } from 'src/entity/novel/novel';
import { NovelService } from 'src/service/novel.service';
import { UserService } from 'src/service/user.service';
import { Repository } from 'typeorm';



@ApiBearerAuth()
@Controller('/api')
export class APIController {
  @Inject()
  ctx: Context;

  @Inject()
  NovelService: NovelService;
  @Inject()
  UserService:UserService;
  @InjectEntityModel(NovelEntity)
  NovelModel: Repository<NovelEntity>;


  @Post('/getnovel')
  async getnovel(@Body() uid) {
   //   return  'Hello Midwayjs12312312!'
     return  this.NovelService.getNovel( uid.data )
  }
  @Post('/getextension')
  async getextension(@Body() uid) {
   //   return  'Hello Midwayjs12312312!'
     return  this.NovelService.getextension()
  }


  @Post('/getnovelitem')
  @Validate()
  async getnovelitem(@Body() data:novelnumDTO) {
   console.log( 'darta',data);
   
     return  this.NovelService.getNovelitem( data )
  }

  
  @Post('/xs/login')
  async Adminlogin(@Body() userinfo: loginDTO ) {
    //  用户号跟密码
   //   return  'Hello Midwayjs12312312!'
        return this.UserService.adminlogin(userinfo)
  }

  
  @Post('/weeknovel')
  async weeknovel( @Body() body) {
      //  获取每周推荐
     return  { }
  }
  @Post('/novellist')
  async novellist( @Body() body:novellistDTO) {
      //  获取每周推荐

     return  this.NovelService.novellist(body)

  }




  @Post('/novellistNum')
  async novellistNum( @Body() body:novellistDTO) {
      //  获取每周推荐
      // body.AndWhere =  { approveStatus:[1]} 
      console.log("novellistNumbody",body);
      // body.AndWhere['approveStatus']=[1]
     return  this.NovelService.adminPagelist(  body ,  
      { 
        keyWordLikeFields :['name','author','id']  , 
    //  leftJonin:['novel.novels','novels']  ,
        count:['a.partSum', 'a.novels']
    } , this.NovelModel )

  }
  // 获取某部小说信息
  @Post('/noveinfoNum')
  async novellistNumone( @Body() body:novelnumDTO) {
      //  获取每周推荐
  
     return  this.NovelService.novellistNumone(  body  )

  }





  // @Post('/setredis')
  // async setredis( @Body() body) {
  //     //  获取
  //    return  this.NovelService.setredis(body)

  // }
  // @Post('/getredis')
  // async getredis( @Body() body) {
  //     //  获取
  //    return  this.NovelService.getredis(body)

  // }

  // @Post('/mysqltext')
  // async mysqltext( @Body() body) {
  //     //  获取
  //    return  this.NovelService.test()

  // }
}


